<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel='stylesheet' href='../rurple.css' type='text/css'>
<title>Amazing - part 4</title>
</head>
<body>
<h2 class="title">20. Amazing - part 4</h2>
<p>As you most likely found out, we were too hasty in asking Reeborg to move
forward after putting down a beeper. We need to check if there is a wall
preventing him from moving first. Here's a solution to the problem.</p>
<pre>
<span class="keyword">def</span> turn_right():
    repeat(turn_left, 3)

put_beeper()
<span class="comment"># begin changes</span>
<span class="keyword">if not</span> front_is_clear():
    turn_left()
<span class="comment"># end changes</span>
move()
<span class="keyword">while not</span> on_beeper():
    <span class="keyword">if</span> right_is_clear():
        turn_right()
        move()
    <span class="keyword">elif</span> front_is_clear():
        move()
    <span class="keyword">else</span>:
        turn_left()

turn_off()
</pre>
<p>Test it now and see that it works. Can you imagine situations where it
might not work?</p>
<center><a href="19-amazing3.htm"><img alt="previous" src=
"../../images/previous.png"> Amazing - part3</a> - <a href=
"../lessons_toc.htm"><img alt="home" src="../../images/home.png"></a> - <a href=
"21-amazing5.htm">Amazing - part 5 <img alt="next" src=
"../../images/next.png"></a>
</center>
</body>
</html>
